﻿
namespace Pibby.Core
{
	using System;
	using System.Runtime.Serialization;
	using System.Security.Permissions;

	/// <summary>
	/// "Easily" identifiable exception 
	/// </summary>
	[Serializable]
	public class TrackedException : Exception
	{
		public TrackedException()
			: base()
		{
			this.Id = Guid.NewGuid();
		}

		public TrackedException(string message)
			: base(message)
		{
			this.Id = Guid.NewGuid();
		}

		public TrackedException(string message, Exception innerException)
			: base(message, innerException)
		{
			this.Id = Guid.NewGuid();
		}

		protected TrackedException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			if (info == null)
			{
				throw new System.ArgumentNullException("info");
			}

			this.Id = new Guid((string)info.GetValue("Id", typeof(string)));
		}

		public Guid Id
		{
			get;
			private set;
		}

		[SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.SerializationFormatter)]
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);

			if (info == null)
			{
				throw new System.ArgumentNullException("info");
			}

			info.AddValue("Id", this.Id.ToString());
		}
	}
}